package com.space.netspider;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;

/**
 * @Author Administrator
 * @Date 2021/6/15 0015 14:46
 * @Version 1.0
 */
public class WriteExcel {

    public static void write(String outPath,String sheetName, List<LawyerBean> lawyerBeanList) throws Exception {
        FileInputStream fs=new FileInputStream(outPath);
        POIFSFileSystem ps=new POIFSFileSystem(fs);
        HSSFWorkbook workbook= new HSSFWorkbook(ps);
        Sheet sheet = workbook.createSheet(sheetName);
        for(int i = 0;i < lawyerBeanList.size();i++){
            LawyerBean lawyerBean = lawyerBeanList.get(i);
            Row row = sheet.createRow(i);
            Cell name = row.createCell(0);
            Cell tel = row.createCell(1);
            Cell company = row.createCell(2);
            Cell addr = row.createCell(3);
            Cell goods = row.createCell(4);
            name.setCellValue(lawyerBean.getName());
            tel.setCellValue(lawyerBean.getTel());
            company.setCellValue(lawyerBean.getCompany());
            addr.setCellValue(lawyerBean.getAddr());
            goods.setCellValue(lawyerBean.getGoods());

        }
        FileOutputStream fos=new FileOutputStream(outPath);
        workbook.write(fos);
        fos.flush();
        fos.close();
    }
}
